import { Application } from "maishu-chitu-react";
import * as ui from "maishu-ui-toolkit";
import { USER_APP } from "common";

const loadingClassName = 'loading';
export function errorHandle(err: Error, app?: Application) {

    if (app == null) {
        app = window[USER_APP];
    }

    if (err.name == "601") {
        if (this.showLoginPage) {
            return;
        }

        this.showLoginPage = true;
        console.assert(app != null);
        var currentPage = app.currentPage;
        app.showPage('user/login', { return: currentPage.url });
        // setTimeout(() => {
        this.showLoginPage = false;
        //     currentPage.close();
        // }, 800);
        return;
    }
    // let loadingElement = this.element.querySelector(`.${loadingClassName}`) as HTMLElement;
    // if (loadingElement) {
    //     this.renderError();
    // }
    // else {
    // alert(err.message);
    ui.alert({ title: '错误', message: err.message });
    // console.log(err);
    // }
}